﻿





#pragma once

#include <assert.h>
#include <iostream>
#include <sstream>
#include <string>
using std::string;
using std::wstring;
#include <vector>


#ifdef WIN32
#include <windows.h>

#pragma warning( disable : 4290 )
#pragma warning( disable : 4996 ) 


namespace ksff
{

	inline size_t file_size(FILE* const f)
	{
		unsigned long old_pos = ftell (f);
		fseek (f, 0, SEEK_END);
		size_t res = (size_t)ftell (f);
		fseek (f, old_pos, SEEK_SET);
		return res;
	}


	
	bool is_file_exests( const string&  filename );
	bool is_file_exests( const wstring& filename );

	bool is_directory_exests( const string&  directory_ );
	bool is_directory_exests( const wstring& directory_ );

	string   get_extention(const string&   filename);
	wstring  get_extention(const wstring&  filename);

	string  set_extention(const string&  filename, const string&  new_extention);
	wstring set_extention(const wstring& filename, const wstring& new_extention);

	string   get_directory (const string&   fullpath);
    wstring  get_directory (const wstring&  fullpath);

	string  get_filename(const string&   fullpath);
	wstring get_filename(const wstring&  fullpath);


	void split( string&  directory_, string&  file_, string& extention_,  const string&  fullpath );
	void split( wstring& directory_, wstring& file_, wstring& extention_, const wstring& fullpath );


	bool set_directory_up( string&  directory_  );
	bool set_directory_up( wstring& directory_ );



	void create_directory( string&  directory_ ) throw (std::runtime_error);
	void create_directory( wstring& directory_ ) throw (std::runtime_error);

	string  get_fullpath( const string&  filename );
	wstring get_fullpath( const wstring& filename );

	string get_shortpath(  const string&  src );
	wstring get_shortpath( const wstring& src );

	void save_to_file(const void* data, const size_t len, const string&  filename)  throw (std::runtime_error);
	void save_to_file(const void* data, const size_t len, const wstring& filename)  throw (std::runtime_error);

	void save_to_file(const string& txt, const string&  filename)  throw (std::runtime_error) ;
	void save_to_file(const string& txt, const wstring& filename)  throw (std::runtime_error) ;

	void load_from_file_binary( std::vector<BYTE>& dest, const string& filename  ) throw(std::runtime_error);
	void load_from_file_binary( std::vector<BYTE>& dest, const wstring& filename ) throw(std::runtime_error);
 
	void load_from_file(string& dest, const string&  filename)  throw (std::runtime_error) ;
	void load_from_file(string& dest, const wstring& filename)  throw (std::runtime_error) ;


	string  get_exe_fullpath_ansi();
	wstring get_exe_fullpath_wide();

	string  get_exe_directory_ansi();
	wstring get_exe_directory_wide();

	string  get_module_directory_ansi( HMODULE );
	wstring get_module_directory_wide( HMODULE );


	bool search_directory_up( string&  dest, const string&  sub_directory_, const string&  start_directory_fullname ) ;
	bool search_directory_up( wstring& dest, const wstring& sub_directory_, const wstring& start_directory_fullname ) ;

	void search_files(std::vector<string>&  dest, const string&  directory_, string&  extentions, bool includeSubFolders);
	void search_files(std::vector<wstring>& dest, const wstring& directory_, wstring& extentions, bool includeSubFolders);




}

#endif // WIN32